package com.滑动窗口的最大值;

import java.util.ArrayList;
import java.util.LinkedList;
import java.util.Queue;
public class Solution {
    public ArrayList<Integer> maxInWindows(int [] num, int size)
    {
    	Queue<Integer> q = new LinkedList<Integer>();
    	ArrayList<Integer> list = new ArrayList<Integer>();
        if(size==0||size>num.length)return list;
    	int max=Integer.MIN_VALUE;
    	int index=0;
    	while(index<=num.length) {
    		
    		if(q.size()>=size) {
    			q.poll();
    			
    			list.add(max);
    			if(index==num.length)break;
    			max=Integer.MIN_VALUE;
    			for(int a:q) {
    				max=Math.max(max, a);
    			}
    		}
    	    max=Math.max(max, num[index]);
    	    q.add(num[index]);
    	    index++;
    	}
		return list;
        
    }
}
